package com.eulog.gwt.euloggwtlibrary.user.client.ui;

import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.Widget;

public class MouseEventImage extends Image implements ClickListener, MouseListener, MouseEventListenerFromCollection{
	
	protected String styleNameMouseOver;
	protected String styleNameMouseClick;
	
	public MouseEventImage(String url) {
		super(url);
		
		init();
	}
	
	public MouseEventImage(String url,String styleName) {
		super(url);
		
		setStyleName(styleName);
		init();
	}
	
	void init() {
		initStyleName();
		
		addClickListener(this);
		addMouseListener(this);
		sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK);
		
	}
	
	void initStyleName() {
		styleNameMouseOver = getStyleName()+"-over";
		styleNameMouseClick = getStyleName()+"-click";
	}
	
	@Override
	public void setStyleName(String style) {
		super.setStyleName(style);
		initStyleName();
	}
	
	public void onClickFromCollection(Widget sender) {
		removeStyleName(styleNameMouseClick);
	}
	
	public void onMouseDownFromCollection(Widget sender, int x, int y) {}
	public void onMouseEnterFromCollection(Widget sender) {}
	public void onMouseLeaveFromCollection(Widget sender) {}
	public void onMouseMoveFromCollection(Widget sender, int x, int y) {}
	public void onMouseUpFromCollection(Widget sender, int x, int y) {}
	
	public void onClick(Widget sender) {
		addStyleName(styleNameMouseClick);
	}
	
	public void onMouseDown(Widget sender, int x, int y) {}
	public void onMouseEnter(Widget sender) {addStyleName(styleNameMouseOver);}
	public void onMouseLeave(Widget sender) {removeStyleName(styleNameMouseOver);}
	public void onMouseMove(Widget sender, int x, int y) {}
	public void onMouseUp(Widget sender, int x, int y) {}
	
}
